#include "main.h"

void get_av_node(void)
{
    FILE * file = 0;
    char buf[128] = {0};
    char *p = NULL;
    char *c,*d;

    file = popen("arecord -l |grep USB2.0","r");   
    fread(buf,1,sizeof(buf),file);
    p = buf;
    while(*p != ':')
        p++;
    p--;
    c = p;
    p+=2;
    while(*p != ':')
        p++;
    p--;
    d = p;
    sprintf(ai_node,"plughw:%c,%c",*c,*d);
    // printf("%s\n",ai_node);
    fclose(file);

    memset(buf,0,sizeof(buf));
    
    file = popen("arecord -l |grep rockchipi2s0sou","r");   
    fread(buf,1,sizeof(buf),file);
    p = buf;
    while(*p != ':')
        p++;
    p--;
    c = p;
    p+=2;
    while(*p != ':')
        p++;
    p--;
    d = p;
    sprintf(ao_node,"plughw:%c,%c",*c,*d);
    // printf("%s\n",ao_node);
    fclose(file);
}

void *pthread_ctl(void * arg)
{
    arg = arg;
    key_fd = open("/dev/input/event1",O_RDWR);
    
    struct input_event inev;
    while(1)
	{
		read(key_fd,&inev,sizeof(inev));
		if(inev.type == EV_KEY)
		{
			if(inev.code == KEY_1)
			{
				if(inev.value == 1)
				{
					if(beep_fd > 0)
                    {
                        close(beep_fd);
                        beep_fd = 0;
                    }
                    else
                    {
                        if(pwd_fd == 0)
                            pwd_fd = open("/dev/pwmled",O_RDWR);
                        else
                            close(pwd_fd);
                    }
				}
			}
		}
		memset(&inev,0,sizeof(inev));
	}

}
